<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <!-- 判断条件和item有关的情况下，可以使用计算属性先过滤再循环 -->
      <!-- 判断条件和item无关的情况下，可以将v-if提到外层 -->
      <h2>if和for不推荐一起使用 - vue2</h2>
      <ul>
        <!-- 在vue2里面v-for的优先级高于v-if -->
        <!-- <li v-for="item in list" v-if="item % 2">{{ item }}</li> -->
        <li v-for="item in oddList">{{ item }}</li>
      </ul>

      <ul v-if="show">
        <li v-for="item in list">{{ item }}</li>
      </ul>
    </div>

    <script src="./lib/vue2.js"></script>
    <script>
      new Vue({
        data() {
          return {
            list: [1, 2, 3, 4, 5, 6, 7],
            show: true,
          };
        },
        computed: {
          oddList() {
            return this.list.filter((item) => item % 2);
          },
        },
      }).$mount("#app");
    </script>
  </body>
  <html></html>
</html>
